var t = function(t) {
  return t && t.__esModule ? t : {
    default: t
  };
}(require("../../../../utils/toot.js")),
app = getApp(),
e = 0;
var util = require("../../../../utils/util.js")


Page({
data: {
  oldHeight: 50,
  pl_pic: [],
  data_arr: [],
  height: 50,
  urlArr: [],
  page: 0,
  prenumber: 10,
  listPatientBbsReplyVO: [],
  bigFilePath: "",
  smallFilePath: "",
  comFlag: !1,
  loadingBoo: !0,
  moreBoo: !0,
  scrollTop: 0,
  topFlag: !1,
  rcontent: "",
  huifuindex: "",
  addFlag: !0,
  imgUrlList: [],
  detailList: {},
  currindex: 0,
  listPatientBbsReplyVO: [],
  dianj: 0
},
xiugai: function(e) {
  console.log(e)
},
linechange: function(t) {
  console.log(t);
  var e = this,
    a = e.data.oldHeight;
  e.data.height;
  t.detail.lineCount > 4 || (t.detail.heightRpx > a ? e.setData({
    height: t.detail.heightRpx
  }) : e.setData({
    height: a
  }));
},
chooseImage: function(e) {
  var a = this,
    i = a.data.urlArr,
    o = this.data.imgUrlList;
  o.length >= 9 ? a.setData({
    addFlag: !1
  }) : t.default.chooseimageTwo(a, o, i);
  console.log(e)
},
delImage: function(e) {
  var a = this,
    i = this.data.imgUrlList,
    o = e.target.dataset.index;
  t.default.delImg(a, o, i);
},
previewImage: function(t) {
  var a = this.data.imgUrlList,
    i = t.target.dataset.imgindex;
  e.previewImage(t, a, i);
},
previewImg: function(t) {
  console.log(t)
  var current = t.target.dataset.src;
  //预览图片
  var imgs = []
  imgs.push(current)
  wx.previewImage({
    current: current,
    urls: imgs,
  });
},
criticImage: function(t) {
  var a = this.data.listPatientBbsReplyVO,
    i = t.target.dataset.imgindex,
    o = t.currentTarget.dataset.ruid;
  a && a.forEach(function(t) {
    if (t.rid == o) return a = t.estimatePicBigUrl, !1;
  }), e.previewImage(t, a, i);
},
goComment: function(e) {
  console.log(e)
  var that = this
  var a_id = that.data.a_id
  var t = that.data.comFlag;
  var openid = wx.getStorageSync('openid')
  if(openid == '')
  {
    wx.showModal({
      title: '提示',
      content:"请先登录",
      success:function(con)
      {
        if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/sgin/sgin',
            })
          }else{
            wx.switchTab({
              url: '/hyb_yl/tabBar/index/index',
            })
          }
      }
    })
  }else{
    that.setData({
      comFlag: !t,
      a_id: a_id
    });
  }
  
},
getText: function(t) {
  //console.log(t)
  this.setData({
    rcontent: t.detail.value
  });
},
sendBtn: function(e) {
  var that = this,
    usertoux = that.data.avatarUrl,
    a = that.data.imgUrlList,
    adminopenid = e.currentTarget.dataset.adminopenid,
    i = a.length,
    o = "patient/reply/saveReply?token=" + that.data.token;
  // let listPatientBbsReplyVO = that.data.listPatientBbsReplyVO;
  // let hfindex = that.data.huifuindex;
  var pl_id = that.data.pl_id
  console.log(pl_id);
  if(!pl_id){
    console.log("楼主")
    var replyType = 'comment'
    var parentid = 0
    that.setData({
      comFlag: !1,
    })
  }else{
    console.log("回复")
    var replyType = 'reply';
    var parentid = pl_id;
    that.setData({
      // listPatientBbsReplyVO: listPatientBbsReplyVO,
      reviewCommentsFlag: !1,
      replyFlag:!1,
    })
  }
  
  // if (pl_id) {
  //   // let reviewCommentsFlag = {
  //   //   // 判断楼主
  //   //   fromUid: 1,
  //   //   rid: 1,
  //   //   id: 1,
  //   //   fromUidName: that.data.nickName,
  //   //   content: that.data.rcontent,
  //   //   replyType: 'comment',
  //   //   hideFlag: 6
  //   // };
  //   // listPatientBbsReplyVO[hfindex].listPatientBbsReplyReplyVO.push(reviewCommentsFlag);

  //   console.log(pl_id)
    
  //   var replyType = 'reply';
  //   var parentid = pl_id;
  //   that.setData({
  //     // listPatientBbsReplyVO: listPatientBbsReplyVO,
  //     reviewCommentsFlag: !1,
  //     replyFlag:!1,
  //   })
    

  // } else {
  //   var replyType = 'comment'
  //   var parentid = 0
  // }
  //是否是贴主
  var pl_pic = that.data.imgUrlList
  var a_id = that.data.a_id
  var pl_content = that.data.rcontent
  var uniacid = app.siteInfo.uniacid;
  var data_arr = that.data.data_arr;
  var useropenid = wx.getStorageSync('openid') //用户openid 
  var name = that.data.nickName
  if (adminopenid == useropenid) {
    var author = 1
  } else {
    var author = 0
  }
  // if (that.data.comFlag) {
  //   // let comFlag = {
  //   //   userIcon: usertoux,
  //   //   // 判断楼主
  //   //   author: author,
  //   //   name: that.data.nickName,
  //   //   rtimeDay: that.data.time,
  //   //   rid: 1,
  //   //   ruid: 1,
  //   //   rcontent: that.data.rcontent,
  //   //   estimatePicSmallUrl: that.data.imgUrlList,
  //   //   listPatientBbsReplyReplyVO: [],
  //   //   allFlag: 1
  //   // };
  //   // listPatientBbsReplyVO.push(comFlag);
  //   that.setData({
  //     // listPatientBbsReplyVO: listPatientBbsReplyVO,
  //     comFlag: !1,
  //     // imgUrlList: []
  //   })
  // }
  var data_arr1 = that.data.data_arr; //图片
  app.util.request({
    'url': 'entry/wxapp/share.pinglunadd',
    data: {
      pl_content: that.data.rcontent,
      adminopenid: adminopenid,
      useropenid: useropenid,
      a_id: a_id,
      data_arr1: data_arr1,
      types: 0,
      usertoux: usertoux,
      name: name,
      author: author,
      replyType: replyType,
      parentid: parentid,
    },
    success: function(res) {
      console.log(res)
      that.getAllpinglun(a_id)
    }
  })

},
toLike: function(e) {
  var a = this;
  var  dianzan = a.data.dianzan;
  var a_id = a.data.a_id;
  console.log(dianzan);
  var openid = wx.getStorageSync('openid');
  if(openid == '')
  {
    wx.showModal({
      title: '提示',
      content:'请先登录',
      success:function(con)
      {
        if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/sgin/sgin',
            })
          }else{
            wx.switchTab({
              url: '/hyb_yl/tabBar/index/index',
            })
          }
      }
    })
  }else if (dianzan == 0) {
    app.util.request({
      'url': 'entry/wxapp/share.userdianz',
      data: {
        op: 'dianzan',
        parentid: a_id,
        openid: wx.getStorageSync('openid'),
      },
      success: function(res) {
        wx.showToast({
          title: "点赞成功",
          icon: "none",
          duration: 1500,
          success: function() {
            a.setData({
              dianzan: 1
            })
          }
        });
      }
    })
  } else {
    wx.showToast({
      title: "点赞是严肃的，不可以反悔哦！",
      icon: "none",
      duration: 1500
    });
  }
},
moreState: function() {
  // var e = this;
  // e.data.loadingBoo && e.data.moreBoo && (e.setData({
  //   loadingBoo: !1
  // }), t.default.getDetails(e, 1));
},
bindscroll: function(t) {
  // t.detail.scrollTop > this.data.windowHeight ? this.setData({
  //   topFlag: !0
  // }) : this.setData({
  //   topFlag: !1
  // });
},
toTop: function(t) {
  this.setData({
    topFlag: !1,
    scrollTop: 0
  });
},
remove: function(t) {
  var a = this;
  var a_id = a.data.a_id
  wx.showModal({
    title: "确认删除动态吗",
    confirmColor: "#3b4ca9",
    success: function(t) {
      if (t.confirm) {
        app.util.request({
          'url': 'entry/wxapp/share.deletecontent',
          data: {
            a_id: a_id
          },
          success: function(res) {
            console.log(res)
            wx.showToast({
              title: '删除成功',
              icon: 'none',
              duration: 2e3,
              success: function() {
                setTimeout(function() {
                  wx.navigateBack({
                    detail: 1
                  })
                }, 2000)
              }
            })
          },
          fail: function(err) {
            console.log(err)
          },
        })
      }
    }
  })
},
onLoad: function(options) {
  var that = this
  var a_id = options.a_id
  var time = util.formatTime(new Date());
  var bgc = wx.getStorageSync('color')
  var userInfo = wx.getStorageSync('userInfo')
  var useropenid = wx.getStorageSync('openid')
  if (userInfo.u_thumb) {
    var avatarUrl = userInfo.u_thumb
    var nickName = userInfo.u_name
  } else {
    var avatarUrl = userInfo.avatarUrl
    var nickName = userInfo.nickName
  }
  console.log(userInfo)
  wx.setNavigationBarColor({
    frontColor: "#ffffff",
    backgroundColor: bgc,
  })
  var typs = options.typs;
  var f_id = options.f_id;
  var j_id = options.j_id;
  if(typs == 'suifang')
  {
    app.util.request({
      'url':"entry/wxapp/follow.add_visit",
      data:{
        id:a_id,
        j_id:j_id,
        openid:wx.getStorageSync('openid'),
        type:0,
        f_id:f_id
      }
    })
  }
  that.setData({
    a_id: a_id,
    userInfo: userInfo,
    avatarUrl: avatarUrl,
    time: time,
    bgc: bgc,
    nickName: nickName,
    useropenid: useropenid
  })
  app.util.request({
    'url': 'entry/wxapp/share.addliulannum',
    data: {
      a_id: a_id,
    },
  })
  app.util.request({
    'url': 'entry/wxapp/share.datainfo',
    data: {
      a_id: a_id,
      openid:wx.getStorageSync('openid'),
    },
    success: function(res) {
      console.log(res.data)
      that.setData({
        detailList: res.data,
        dianzan:res.data.dianzan,
      })
    },
    fail: function(err) {
      console.log(err)
    },
  })
  this.getAllpinglun()
  
  var uniacid = app.siteInfo.uniacid;
  app.util.request({
    'url': 'entry/wxapp/share.url',
    'cachetime': '0',
    success: function(res) {
      console.log(res)
      that.setData({
        url: res.data,
        uniacid: uniacid
      })
    },
  })
},
onReady: function() {},
reviewComments: function(t) {
  console.log(t)
  this.data.pl_id = t.currentTarget.dataset.pl_id
  this.data.toUid = t.currentTarget.dataset.toid
  this.data.comment = "comment", console.log("回复你")
  var openid = wx.getStorageSync('openid');
  if(openid == '')
  {
    wx.showModal({
      cancelColor: '提示',
      content:"请先登录",
      success:function(con)
      {
        if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/sgin/sgin',
            })
          }else{
            wx.switchTab({
              url: '/hyb_yl/tabBar/index/index',
            })
          }
      }
    })
  }else{
    this.setData({
      reviewCommentsFlag: !0,
      comFlag: !1,
      rcontent: "",
      huifuindex: t.currentTarget.dataset.index
    });
  }
  
},
removepl(e) {
  var that = this
  var pl_id = e.currentTarget.dataset.pl_id
  var a_id = that.data.a_id
  wx.showModal({
    content: '确定删除该评论？',
    success: function(res) {
      if (res.confirm) {
        app.util.request({
          'url': 'entry/wxapp/share.deletepl',
          data: {
            pl_id: pl_id,
          },
          success: function(res) {
            console.log(res)
            that.getAllpinglun(a_id)
          }
        })
      }
    }
  })

},
reply: function(t) {
  this.data.comment = "reply", this.data.commentId = t.currentTarget.dataset.commentid,this.data.pl_id = t.currentTarget.dataset.pl_id,this.data.huifuindex=t.currentTarget.dataset.index,
    this.data.toUid = t.currentTarget.dataset.toid, this.setData({
      replyFlag: !0,
      comFlag: !1,
      rcontent: "",
      byReplyName: t.currentTarget.dataset.name
    });
},
mask: function() {
  this.setData({
    reviewCommentsFlag: !1,
    replyFlag: !1,
    huifuindex: ""
  });
},
removeBtn: function(t) {
  console.log(t);
  var a = this,
    i = t.currentTarget.dataset.index;
  var pl_id = t.currentTarget.dataset.pl_id
  var a_id = a.data.a_id
  wx.showModal({
    content: '确定删除该评论吗？',
    success: function(res) {
      if (res.confirm) {
        app.util.request({
          'url': 'entry/wxapp/share.deletepl',
          data: {
            pl_id: pl_id,
          },
          success: function(res) {
            console.log(res)
            a.getAllpinglun(a_id)
          }
        })
        wx.showToast({
          title: "删除成功",
          icon: "none",
          duration: 2e3
        })
      }
    }
  })

},
commentEach: function(a) {
  var i = this;
  wx.request({
    url: app.globalData.patient + "patient/reply/savePatBbsReplyReply",
    method: "POST",
    header: {
      "content-type": "application/x-www-form-urlencoded"
    },
    data: {
      rid: i.data.commentId,
      replyType: a,
      content: i.data.rcontent,
      toUid: i.data.toUid,
      token: i.data.token
    },
    success: function(e) {
      // console.log(e), 200 == e.data.code && 
      (i.setData({
        reviewCommentsFlag: !1,
        replyFlag: !1,
        rcontent: "",
        moreBoo: !0,
        page: 0
      }), t.default.getDetails(i, 0));
    }
  });
},
changeList: function(t) {
  console.log(t), this.data.fatherIndex = t.currentTarget.dataset.index;
  this.data.ruid = t.currentTarget.dataset.ruid;
},
lookMore: function(t) {
  console.log(t);
  var e = t.currentTarget.dataset.index;
  this.data.listPatientBbsReplyVO[e].allFlag = !0, this.data.listPatientBbsReplyVO[e].listPatientBbsReplyReplyVO.forEach(function(t) {
    t.hideFlag = !0;
  }), this.setData({
    listPatientBbsReplyVO: this.data.listPatientBbsReplyVO
  });
},

//查询当前分享的所有评论
getAllpinglun: function() {
  var that = this
  var a_id = that.data.a_id
  app.util.request({
    'url': 'entry/wxapp/share.allpinglunlist',
    data: {
      a_id: a_id,
    },
    success: function(res) {
      console.log(res)
      that.setData({
        listPatientBbsReplyVO: res.data
      })
    }
  })
},

});